package hellfire.game;

import hellfire.game.weapons.AbstractWeapon;
import hellfire.game.weapons.Ball;
import hellfire.game.weapons.Bomb;
import hellfire.platform.graphics.GameRenderer;
import hellfire.platform.input.GameListener;
import hellfire.system.graphics.GLRelVec2;
import hellfire.system.graphics.GLVec2;
import hellfire.system.graphics.UI;

import java.util.Vector;

import android.util.Log;

public class Game 
{
	private Vector<Chicken> chickens = new Vector<Chicken>();
	private Vector<ChickenDebris> chickenDebris = new Vector<ChickenDebris>();
	private Vector<AbstractWeapon> weapons = new Vector<AbstractWeapon>();
	private GameRenderer renderer;
	
	public Game()
	{
		
		chickens = new Vector<Chicken>();
		for(int i = 0; i < 20; i++) chickens.add(new Chicken(this));
		
		weapons.add(new Ball(new GLVec2(0,0), this));
		//weapons.add(new Bomb(new GLVec2(0,0), this));
		//chickens.add(c1);
		//chickens.add(c2);
		
		renderer = new GameRenderer(this);
	}
	
	public Object getObjectAtPoint(GLVec2 point, Class filter, float radius)
	{
		if(filter.equals(Chicken.class))
		{
			for(Chicken c : chickens)
			{
				GLVec2 pos = c.getRenderPos();
				if(UI.testInRange(pos, radius, point))
					return c;
			}
		}
		return null;
	}
	
	public Vector<Object> getObjectsAtPoint(GLVec2 point, Class filter, float radius)
	{
		Vector<Object> ans = new Vector<Object>();
		if(filter.equals(Chicken.class))
		{
			for(Chicken c : chickens)
			{
				GLVec2 pos = c.getRenderPos();
				if(UI.testInRange(pos, radius, point))
					ans.add(c);
			}
		}
		return ans;
	}
	
	public Vector<Chicken> getChickens()
	{
		return chickens;
	}
	
	public Vector<ChickenDebris> getChickenDebris()
	{
		return chickenDebris;
	}
	
	public Vector<AbstractWeapon> getWeapons() 
	{
		return weapons;
	}
	
	public GameRenderer getRenderer()
	{
		return renderer;
	}
	
	public void gameFrame()
	{
		for(int i = 0; i < chickens.size(); i++)
		{
			Chicken c = chickens.get(i);
			c.gameFrame(this);
		}
		
		for(int i = 0; i < chickenDebris.size(); i++)
		{
			ChickenDebris cd = chickenDebris.get(i);
			cd.gameFrame(this);
		}
		
		for(int i = 0; i < weapons.size(); i++)
		{
			AbstractWeapon weapon = weapons.get(i);
			weapon.gameFrame();
		}
	}

	
}
